# coding: utf-8
# @Author : lryself
# @Date : 2020/11/3 21:10
# @Software: PyCharm
from flask_restplus import Resource

from . import main_rest_api, back_model
from ..service.informationCodeManager import InformationCodeManager
from ..service.informationInfoManager import InformationInfoManager

material_get_parser = main_rest_api.parser()
material_get_parser.add_argument('ParentCodeID', type=str, location='args', required=True)


class MaterialResource(Resource):
    @main_rest_api.doc(description="获取资料信息")
    @main_rest_api.marshal_with(back_model, skip_none=True)
    @main_rest_api.expect(material_get_parser)
    def get(self):
        kwargs = material_get_parser.parse_args()

        result_dict = InformationInfoManager.get_information_by_parentID(kwargs.get("ParentCodeID"))

        return result_dict


class MaterialListResource(Resource):
    @main_rest_api.doc(description="获取资料结点信息")
    @main_rest_api.marshal_with(back_model, skip_none=True)
    @main_rest_api.expect(material_get_parser)
    def get(self):
        kwargs = material_get_parser.parse_args()

        result_dict = InformationCodeManager.get_codeList_by_parentCodeID(ParentCodeID=kwargs.get("ParentCodeID"))

        return result_dict
